/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2012-10-23         luwei
 */

package com.skyworth.ui.customview;

import android.view.View;
import android.view.ViewGroup;

import java.util.List;


/**
 * 自定义的adapter，目前可用于ISimpleListview
 * @param <T> 刷新UI的数据
 */
public abstract class BaseAdapter<T> {
    public interface ObserverListener {
        public void onChanaged();
    }

    public BaseAdapter(){
    }

    protected SlideFocusView.FocusChangedEvent focusChangedEvent = null;
    protected SlideFocusView.FocusViewRevision revision = null;
    public void setFocusEvent(SlideFocusView.FocusChangedEvent focusChangedEvent, SlideFocusView.FocusViewRevision revision) {
        this.focusChangedEvent = focusChangedEvent;
        this.revision = revision;
    }

    protected ObserverListener mObserver = null;

    /**
     * 获取总数
     * @return
     */
    public abstract int getCount();

    /**
     * 获取指定位置的数据
     * @param pos
     * @return
     */
    public abstract T getItemData(int pos);

    /**
     * 刷新UI
     * @param datas
     */
    public abstract void refreshUI(List<T> datas);

    /**
     * 获取View
     * @param position 位置
     * @param convertView 是否可以利用view
     * @param parent 父view
     * @return
     */
    public abstract View getView(int position, View convertView, ViewGroup parent);

    /**
     * 回收
     */
    public abstract void destroy();

    /**
     * 通知开始刷新界面
     */
    public void notifyDataSetChanaged() {
        if (mObserver != null) {
            mObserver.onChanaged();
        }
    }

    /**
     * 注册观察者，发现有数据变化，就通知刷新
     * @param listener
     */
    public void registObserver(ObserverListener listener) {
        mObserver = listener;
    }
}
